#include<bits/stdc++.h>
#define int long long
using namespace std;
set<int>s;
const int N = 4e5 + 10;
int sum[N];
signed main() {
	freopen("kte.in", "r", stdin);
	freopen("kte.out", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int T;
	cin >> T;
	while(T--) {
		int x;
		cin >> x;
		if(s.count(x)) s.erase(x);
		else s.insert(x);

		vector<int>v;
		int cnt = 0;
		for(int i : s) {
			v.push_back(i);
			++cnt;
			sum[cnt] = sum[cnt - 1] + i;
		}
		int len = v.size();
		int now = 0, pre = 0, ans = 0;
		for(int i = len - 1; i >= 0; i--) {
			now += v[i];
			ans += now - max(pre, sum[len - i]);
			pre = now;
		}
		
		cout << ans << endl;
	} 
	return 0;
}

